<%@ page language="java" pageEncoding="UTF-8" contentType="image/jpeg" %>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.*"%>
<%!
Color getColor(){
	int r=(int)(Math.random()*155)+100;
	int g=(int)(Math.random()*155)+100;
	int b=(int)(Math.random()*155)+100;
	return new Color(r,g,b);
}
%>
<%
response.setHeader("Pragma","No-cache"); 
response.setHeader("Cache-Control","no-cache"); 
response.setDateHeader("Expires", 0); 

int width=70;
int height=25;
BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g=image.getGraphics();
g.setColor(getColor());
//g.drawLine(0,0,100,30);
char[] s=new char[4];
for(int i=0;i<4;++i){
	int j=(int)(Math.random()*36);
	if(j<10){
		s[i]=(char)('0'+j);
	} else if(j<36){
		s[i]=(char)('A'+j-10);
	} else {
		s[i]='0';
	}
}
g.setFont(new Font("Times New Roman", Font.PLAIN, 20));
g.drawString(new String(s),10,20);
session.setAttribute("code",new String(s));
for(int i=0;i<80;++i){
	int x=(int)(Math.random()*width);
	int y=(int)(Math.random()*height);
	int xx=x+(int)(Math.random()*6)-3;
	int yy=y+(int)(Math.random()*6)-3;
	g.drawLine(x,y,xx,yy);
}
g.dispose();
ImageIO.write(image,"JPEG",response.getOutputStream());
out.clear();
out = pageContext.pushBody();
%>
